package wortubung.wordlist;

import wortubung.WortUbung;

import static wortubung.util.CommonUtils.*;

public class PrintOptions extends WordQuery {
	private boolean isWordsOnly;
    private boolean isComplete;
    private boolean includeListName;
    private boolean includeLevel;
    private boolean includeNounCategory;
    private boolean groupByList;

    public boolean isComplete() { return !isWordsOnly && isComplete; }
    public boolean isWordsOnly() { return isWordsOnly; }
    public boolean includeListName() { return includeListName; }
    public boolean includeLevel() { return includeLevel; }
    public boolean includeNounCategory() { return includeNounCategory; }
    public boolean groupByList() { return groupByList; }

    public void setIsComplete(boolean value) { isWordsOnly = false; isComplete = value; }
    public void setIsWordsOnly(boolean value) { isWordsOnly = value; }
    public void setIncludeListName(boolean value) { includeListName = value; }
    public void setIncludeLevel(boolean value) { includeLevel = value; }
    public void setIncludeNounCategory(boolean value) { includeNounCategory = value; }
    public void setGroupByList(boolean value) { groupByList = value; }

    public PrintOptions(WortUbung dictionary) { this(dictionary, null); }

    public PrintOptions(WortUbung dictionary, String params) {
    	super(dictionary, params);

    	isComplete = false;
    	includeListName = false;
    	includeLevel = false;
    	includeNounCategory = false;
    	
    	if (isHelp())
    		return;
		for (String opt : params.split(" +")) {
			String[] keyVal = opt.split("=");
			boolean isYes = (keyVal.length < 2) || checkBoolean(keyVal[1]);
			if ("complete".equals(opt))
				setIsComplete(true);
			else if ("simple".equals(opt))
				setIsComplete(false);
			else if ("wordsonly".equalsIgnoreCase(opt))
				setIsWordsOnly(true);
			else if ("showlistname".equalsIgnoreCase(keyVal[0]))
				setIncludeListName(isYes);
			else if ("showlevel".equalsIgnoreCase(keyVal[0]))
				setIncludeLevel(isYes);
			else if ("shownouncat".equalsIgnoreCase(keyVal[0]))
				setIncludeNounCategory(isYes);
		}
    }

    public void showHelp() {
    	promptln("    complete                       Print complete information about words.\n" +
   	             "    simple                         Print brief information about words.\n" +
	             "    wordsOnly                      Print words without definitions.\n" +
    	         "    showListName[=yes|no]          Print list name. Without value means yes.\n" +
    	         "    showLevel=[yes|no]             Print level. Without value means yes.\n" +
    	         "    showNounCat=[yes|no]           Print noun category. Without value means yes.\n" +
    	         super.getHelpText());
	}
}
